<!DOCTYPE html>
<html>
<head>
	<title>我的游记</title>
	<meta charset="utf-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
	<link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
	<script src="/js/jquery/jquery.min.js"></script>
	<script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
	<script src="/js/plugins/jrender/jrender.min.js"></script>
	<link rel="stylesheet" href="/css/font/css/font-awesome.min.css" />
	<link rel="stylesheet" href="/css/reset.css" />
	<link rel="stylesheet" href="/css/userTravels.css" />
	<link rel="stylesheet" href="/js/plugins/dialog2/dialog.css" />
	<script src="/js/plugins/dialog2/dialog.min.js"></script>

	<script>
        $(function () {
            var currentPage = 1;
            var user = JSON.parse(sessionStorage.getItem("user"));
            //接收总页数
			var pages;
            //定义变量,接收前面查询到的数据
			var beforeData = [];
			//定义标志,判断是否正在发送ajax请求
			var flag = false;
            //将查询请求定义成方法
			function query() {
                if (flag) {
                  return;
                }
                //查询时,设置标志为true
                flag = true;
				$.get("/users/"+user.id+"/travels",{currentPage:currentPage},function (data) {
				    //将查询的数据与原来的数据拼接
					$.merge(beforeData,data.list);
					var json = {list:beforeData};
					$(".travels").renderValues(json,{
					    getHref:function (item,value) {
							$(item).attr("href","/mine/editTravels.html?id="+value);
                        }
					});
					//接收总页数
					pages = data.pages;
					//每查一次,当前页+1
					currentPage++;
					//查询完毕,设置为false
					flag = false;
				});
            }
            //一开始进来时先查询一次
			query();
            //窗口绑定滚动事件
            $(window).scroll(function () {
                //console.log("滚动");
				//如果窗口的高度 + 页面被隐藏的高度 >= 页面的高度,则证明页面到底部了
                if ($(window).height() + $(document).scrollTop() + 0.5 >= $(document).height()) {
                    //console.log("到底部了");
                    if (currentPage <= pages) {
                        query();
                    }else {
                        $(document).dialog({
                            type : 'notice',
                            infoText: '亲,已经到底部啦!',
                            autoClose: 1500,
                            position: 'bottom'  // center: 居中; bottom: 底部
                        });
					}
                }
            });
        });
	</script>
</head>

<body>
<div class="search-head">
	<div class="row nav-search">
		<div class="col">
			<a href="profiles.html">
				<span><i class="fa fa-chevron-left"></i></span>
			</a>
		</div>
		<div class="col">
			<span>我的游记</span>
		</div>
		<div class="col"></div>
	</div>
</div>


<div class="container travels">
	<dl class="list" render-loop="list">
		<dd>
			<a render-key="list.id" render-fun="getHref">
				<img  render-src="list.coverUrl">
				<h6 class="title" render-html="list.title"></h6>
				<p>最近更新时间 <span render-html="list.lastUpdateTime"></span>
					<span class="span-right">
							  <i class="fa fa-heart"></i><span>0</span>收藏
						  <i class="fa fa-thumbs-o-up"></i><span>0</span>点赞</span>
				</p>
			</a>
		</dd>
	</dl>
</div>

</body>
</html>
